package exception;


import java.io.FileOutputStream;
import java.io.IOException;

/**
 *IO操作时的异常处理机制
 */

public class FinallyDemo2 {
    public static void main(String[] args)  {
        FileOutputStream fos = null;
        try {
            fos=new FileOutputStream("fos.dat");
            fos.write(1);
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();//向控制台输出当前异常的错误信息
        } finally {
            try {
                if (fos!=null) {
                    fos.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }
}
